package bold.module.thrift.server;

import bold.module.thrift.genapi.UserI;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;

public class Server2 {

    /**
     * 启动 Thrift 服务器 2
     * <p>
     * processor 处理器
     * transport 运输
     * protocol 协议
     */
    public static void main(String[] xx) throws TTransportException {
        TProcessor tprocessor = new UserI.Processor(new UserService());

        TNonblockingServer.Args args = new TNonblockingServer.Args(new TNonblockingServerSocket(8090))
                .processor(tprocessor)
                .transportFactory(new TFramedTransport.Factory())
                .protocolFactory(new TCompactProtocol.Factory());

        // 使用非阻塞式IO，服务端和客户端需要指定TFramedTransport数据传输的方式
        new TNonblockingServer(args).serve();
        System.out.println(" TNonblockingServer 启动");
    }
}
